<%@page import="com.seniorproject.aims.PasswordHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import = "java.util.List" %>
<%@ page import ="java.util.ArrayList"%>
<%@ page import ="javax.script.Invocable"%>
<%@ page import ="javax.script.ScriptEngine"%>
<%@ page import ="javax.script.ScriptEngineManager"%>
<%@ page import ="java.io.BufferedReader"%>
<%@ page import ="java.io.File"%>
<%@ page import ="java.io.FileInputStream"%>
<%@ page import = "com.seniorproject.aims.*" %>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Enrollment Home</title>
	<link rel="stylesheet" type="text/css" href="css/stylev2.css" />
	
	<style type="text/css">
		a {
	      text-decoration:none;
	   }
	</style>

</head>
<body>

<%


	String strUser = String.valueOf(session.getAttribute("sUser"));
	HttpSession htp_session = request.getSession();
			
	if (htp_session == null || htp_session.getAttribute("sUser") == null) {
	    // Forward the control to login.jsp if authentication fails or session expires
	    request.getRequestDispatcher("/login.jsp").forward(request,
	        response);
	}
	
	if("admin".equals(htp_session.getAttribute("sUser"))){%>
	<script>alert("This user dont have PERMISSION to access this zone.");</script>
	<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=admin_home.jsp"> 	
	<%}
	
		System.out.println("@student_home");	
	
		//get permission 
		
		String name = String.valueOf(session.getAttribute("name"));
		String surname = String.valueOf(session.getAttribute("surname"));
		String role_name = String.valueOf(session.getAttribute("enrollment_role"));
		
		String department_id = String.valueOf(session.getAttribute("department_id"));
		
		int num_system = Integer.parseInt(String.valueOf(session.getAttribute("num_system")));
		
				
		System.out.println("name : " + name);///////////////////////////////
		System.out.println("department_id : " + department_id);/////////////////////////
		System.out.println("num_system : " + num_system);/////////////////////////
		
		
		List<String> system_name = new ArrayList<String>();
		
		Permission permission = new Permission(strUser,name);
		permission.setDepartmentId(department_id);
		permission.setRegisCreate(Boolean.valueOf(String.valueOf(session.getAttribute("enrollment_create"))));
		permission.setRegisDelete(Boolean.valueOf(String.valueOf(session.getAttribute("enrollment_delete"))));
		permission.setRegisRead(Boolean.valueOf(String.valueOf(session.getAttribute("enrollment_read"))));
		permission.setRegisUpdate(Boolean.valueOf(String.valueOf(session.getAttribute("enrollment_update"))));
		
		String permiss = "";
		if(permission.getRegisCreate()) {
			permiss = permiss + "Add";
		}
		if(permission.getRegisUpdate()) {
			if("".equals(permiss)) {
				permiss = permiss + "Edit";
			} else {
				permiss = permiss + " Edit";
			}
		}
		if(permission.getRegisRead()) {
			if("".equals(permiss)) {
				permiss = permiss + "Read";
			} else {
				permiss = permiss + " Read";
			}
		}
		if(permission.getRegisDelete()) {
			if("".equals(permiss)) {
				permiss = permiss + "Delete";
			} else {
				permiss = permiss + " Delete";
			}
		}
		

%>

<div id="page-wrap">
		<div id="inside">
			<table border="0">
				<tr style="font-size:24px">
					<td width="600" height="100" style= "background-color: #273b80;border: 0px ;padding: 0px; 0px;" >
						<div id="header_banner-2"></div>
					</td>
					
					<td width="680" height="100" style= "background-color: #273b80;border: 0px;padding: 0px; 0px;" >
						<p align="right"><label><font size="4" color="#ffffff">username : <%=strUser %> &nbsp;&nbsp;</font></label></p>	
						<a href="logout.jsp"><p align="right"><label style="cursor: pointer;"><font size="3" color="#ffffff">log out &nbsp;</font></label></p></a>
					</td>
				</tr>
			</table>
			<table border="0">
				<tr style="font-size:10px">

					<td width = "720" height="50" style= "background-color:#FFFFFF ; border-bottom-color: #FFFFFF; border-left-color: #FFFFFF">
						<center><h2><font color="#273b80"><label>หน้าแรก</label></font></h2></center>
					</td>
<%
			if(permission.getRegisRead()) {
%>
					<td width = "720" height="50" style= "background-color:#D0D0D0 ;">
						<center><a href="enroll_search.jsp"><h2><font color="#273b80"><label style="cursor: pointer;">ค้นหา</label></font></h2></a></center>
					</td>
					<td width = "720" height="50" style= "background-color:#D0D0D0 ;">
						<center><a href="enroll_summary.jsp"><h2><font color="#273b80"><label style="cursor: pointer;">สรุปผลการลงทะเบียน</label></font></h2></a></center>
					</td>
<%
			}
			if(permission.getRegisCreate()) {
%>
					<td width = "720" height="50" style= "background-color:#D0D0D0 ;">
						<center><a href="enroll_enrollment.jsp"><h2><font color="#273b80"><label style="cursor: pointer;">ลงทะเบียนรายวิชา</label></font></h2></center>
					</td>
					<td width = "720" height="50" style= "background-color:#D0D0D0 ;">
						<center><a href="enroll_timetable.jsp"><h2><font color="#273b80"><label style="cursor: pointer;">ตารางสอน</label></font></h2></a></center>
					</td>
<%
			}
			
%>
				</tr>
			</table>
				
				<div id="main-content-ac">
						<br>
					
						<h2 style="padding-left: 2.5cm; color: #273b80; font-size: 24px;">ยินดีต้อนรับ : <%=permission.getName()%> </h2>
						
						<br><br>
						
						<center>
					
								<table id="detail_table" width="1000" border="1">
						        	<tr style="font-size:24px" >
						        		<td  width="50" height="50" rowspan="4" style="text-align: center;">
						        			<img id="user_image" src="image/user_no_photo.jpg" style="width:130px;height:160px;	">
						        		</td>
						             	<td  width="500" >
						                	<font size="5"><strong>ชื่อ</strong></font>
						                </td>
						                <td width="400" height="50">
						                	<%=name + " " + surname %>
						                </td>
						            </tr>
						                
						                
									<tr style="font-size:24px">
						                <td height="50">
						                	<font size="5"><strong>ตำแหน่ง</strong></font>
						                </td>
						                <td height="50">
						                	<%= role_name %>
						                </td>
						            </tr>
						                
									<tr style="font-size:24px">
						                <td height="50">
						                	<font size="5"><strong>สิทธิการใช้งานในระบบ</strong></font>
						                </td>
						                <td height="50">
						                	<%=permiss %>
						                </td>
						            </tr>
						            
						            <tr style="font-size:24px">
						                <td height="50">
						<%
									if(num_system > 1){
						%>
										<center><a href="system_select.jsp"><font size="3" color="#ffffff"><input type="button" value="เปลี่ยนระบบ" class="buttonStyle" style="cursor: pointer;width:200px;"/></font></a></center>
						<%
									}
						%>
						                </td>
						                <td height="50">
						                	<form id="form1" name="form1" method="post" action="change_password.jsp">
												<input type="hidden" id="mode" name="mode" value="enroll" /> 
												<input type="hidden" id="system" name="system" value="enroll" /> 
												<font size="3" color="#ffffff"><input type="submit" value="เปลี่ยนรหัสผ่าน" class="buttonStyle" style="cursor: pointer;width:200px;"/></font>
												
											</form>
						                </td>
						            </tr>
								</table>
								
  						</center>
  					
					   
								
						<br><br><br><br><br><br><br>
				
			<div style="clear: both;"></div>
			
			
				
			<div id="footer"></div>
			
		</div>		
			<div style="clear: both;"></div>		
   </div>


</body>
</html>